<?php
/**
 ***** 扶摇而上、抱守本真 ******
 * @author Dana
 * @Date 2021/7/5
 */

class myQueue
{
    protected $maxSize;
    protected $array;

    /**
     * @param Integer $k
     */
    function __construct($maxSize)
    {
        $this->maxSize = $maxSize;
        $this->array = [];
    }

    /**
     * @param Integer $value
     * @return Boolean
     */
    function enQueue($value)
    {
        if ($this->isFull()) {
            return false;
        }

        $this->array[] = $value;
        return true;
    }

    /**
     * @return Boolean
     */
    function deQueue()
    {
        if ($this->isEmpty()) {
            return false;
        }

        array_shift($this->array);
        return true;
    }

    /**
     * @return Integer
     */
    function Front()
    {
        if ($this->isEmpty()) {
            return -1;
        }
        reset($this->array);
        return current($this->array);
    }

    /**
     * @return Integer
     */
    function Rear()
    {
        if ($this->isEmpty()) {
            return -1;
        }

        return end($this->array);
    }

    /**
     * @return Boolean
     */
    function isEmpty()
    {
        $flag = false;
        if (count($this->array) == 0) {
            $flag = true;
        }
        return $flag;
    }

    /**
     * @return Boolean
     */
    function isFull()
    {
        $flag = false;
        if (count($this->array) == $this->maxSize) {
            $flag = true;
        }
        return $flag;
    }

    public function list()
    {
        return $this->array;
    }
}


$obj = new myQueue(8);
$ret_1 = $obj->enQueue(3);
$ret_2 = $obj->enQueue(9);
$ret_3 = $obj->enQueue(5);
$ret_4 = $obj->enQueue(0);
$ret_5 = $obj->deQueue();// 3
$ret_6= $obj->deQueue();//1
$ret_7 = $obj->isEmpty();
$ret_8= $obj->isEmpty();
$ret_9 = $obj->Rear();//2
$ret_10 = $obj->Rear();
$ret_11= $obj->deQueue();//5
/*$ret_12 = $obj->list();
$ret_13 = $obj->enQueue(6);
$ret_14 = $obj->enQueue(7);
$ret_15 = $obj->Rear();//6
$ret_16 = $obj->Front();
$ret_17 = $obj->Rear();
$ret_18= $obj->list();*/

echo "ret_1 : {$ret_1} ".PHP_EOL;
echo "ret_2 : {$ret_2} ".PHP_EOL;
echo "ret_3 : {$ret_3} ".PHP_EOL;
echo "ret_4 : {$ret_4} ".PHP_EOL;
echo "ret_5 : {$ret_5} ".PHP_EOL;
echo "ret_6 : {$ret_6} ".PHP_EOL;
echo "ret_7 : {$ret_7} ".PHP_EOL;
echo "ret_8 : {$ret_8} ".PHP_EOL;
echo "ret_9 : {$ret_9} ".PHP_EOL;
echo "ret_10 : {$ret_10} ".PHP_EOL;
echo "ret_11 :{$ret_11} ".PHP_EOL;

/*echo "ret_12 :  ".PHP_EOL;
print_r($ret_12);
echo "ret_13 : {$ret_13} ".PHP_EOL;
echo "ret_14 : {$ret_14} ".PHP_EOL;
echo "ret_15 : {$ret_15} ".PHP_EOL;
echo "ret_16 : {$ret_16} ".PHP_EOL;
echo "ret_17 : {$ret_17} ".PHP_EOL;
echo "ret_18 :\r\n";
    print_r($ret_18);*/